/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package snail.data;

import org.hibernate.Session;
import snail.hibernate.util.HibernateUtil;

/**
 *
 * @author Mickel
 */
public class HibernateDAOFactory extends DAOFactory {

    @Override
    public IUserDAO getUserDAO() {
        return (IUserDAO) instantiateDAO(snail.data.UserDAO.class);
    }

    private GenericHibernateDAO instantiateDAO(Class c) {
        try {
            GenericHibernateDAO dao = (GenericHibernateDAO) c.newInstance();
            dao.setSession(getCurrentSession());
            return dao;
        } catch (Exception ex) {
            throw new RuntimeException("Can not instantiate DAO: " + c, ex);
        }
    }

    protected Session getCurrentSession() {
        return HibernateUtil.getSessionFactory().getCurrentSession();
    }

}

